class SysResult(dict):
    """
    the structure of response result
    """

    def __init__(self, code, msg, data):
        self.setdefault('code', code)
        self.setdefault('msg', msg)
        self.setdefault('data', data)

    def __repr__(self):
        return "{}: {}".format(self.get('code'), self.get('msg'))

    @staticmethod
    def ok(data=None, msg=None):
        code = 0
        result = SysResult(code, msg, data)
        return result

    @staticmethod
    def error(data=None, msg=None):
        code = -1
        result = SysResult(code, msg, data)
        return result

    @staticmethod
    def warning(data=None, msg=None):
        code = 501
        result = SysResult(code, msg, data)
        return result

    @staticmethod
    def not_found(data=None, msg=None):
        code = 404
        result = SysResult(code, msg, data)
        return result

    @staticmethod
    def signature_expired(data=None, msg=None):
        """
        给用户分配的token过期了，需要用户重新登录
        :param data:
        :param msg:
        :return:
        """
        code = 600
        result = SysResult(code, msg, data)
        return result

    @staticmethod
    def not_authenticated(data=None, msg=None):
        """
        该用户没有权限访问当前api
        :param data:
        :param msg:
        :return:
        """
        code = 601
        result = SysResult(code, msg, data)
        return result
